﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LSData
{
    public class MySqlDisposable : IDisposable
    {
        #region 变量定义
        /// <summary>
        /// 释放标记
        /// </summary>
        private bool disposed = false;
        #endregion

        #region 析构函数
        /// <summary>
        /// 析构函数
        /// </summary>
        ~MySqlDisposable()
        {
            Dispose(false);
        }
        #endregion

        #region 方法定义
        /// <summary>
        /// 自定义释放资源
        /// </summary>
        /// <param name="bDispodedByUser">用户干预：是/否</param>
        protected virtual void Free(bool bDispodedByUser) { }
        #endregion

        #region IDisposable Members
        /// <summary>
        /// 释放资源
        /// </summary>
        /// <param name="bDispodedByUser">用户干预：是/否</param>
        protected void Dispose(bool bDispodedByUser)
        {
            if (!this.disposed)
            {
                lock (this)
                {
                    if (!this.disposed)
                    {
                        try
                        {
                            Free(bDispodedByUser);
                        }
                        finally
                        {
                            this.disposed = true;
                        }
                    }
                }
            }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion
    }
}
